// pages/cashService/admin/addAbst/addAbst.js
const { request } = require('../../../../utils/request');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    abst: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    if (options.data) {
      wx.setNavigationBarTitle({
        title: '编辑缴款项目',
      })
      let tempData=JSON.parse(options.data)
      this.setData({
        id: tempData.id,
        abst: tempData.fundName
      })
    } else {
      wx.setNavigationBarTitle({
        title: '新增缴款项目',
      })
    }
  },
  submit() {
    if(!this.data.abst || this.data.abst.length==0){
      wx.showToast({
        title: '请填写缴款项目',
        icon:'none'
      })
      return
    }
    let queryData = {
      id:this.data.id,
      fundName: this.data.abst,
      enableFlag: 'Y'
    }
    if(this.data.id){
      request('/smsk/wechat/fundsource/update', 'POST', queryData).then(res => {
        console.log(res.data)
        if (res.data.code == 0) {
          wx.showToast({
            title: '保存成功',
            icon: 'success'
          })
          setTimeout(() => {
            wx.navigateBack({
              delta: 1,
            })
          }, 1500);
        }
      })
    }else{
      request('/smsk/wechat/fundsource/add', 'POST', queryData).then(res => {
        console.log(res.data)
        if (res.data.code == 0) {
          wx.showToast({
            title: '创建成功',
            icon: 'success'
          })
          setTimeout(() => {
            wx.navigateBack({
              delta: 1,
            })
          }, 1500);
        }
      })
    }
  },

})